import { mapState } from "vuex";

export default {
  computed: {
    ...mapState([
      "cartList",
      "cartChecked",
      "pickCoupon",
      "pickAddr",
      "nowDate",
    ]),
    goodsList() {
      return this.cartList.filter((it) => {
        return this.cartChecked.includes(it.id);
      });
    },
    totalInfo() {
      let num = 0;
      let price = 0;
      for (const it of this.goodsList) {
        num += it.num;
        price += it.num * it.price;
      }
      price = price.toFixed(2);
      return {
        num,
        price,
      };
    },
    addrInfo() {
      return this.pickAddr.area_info;
    },
  },
  methods: {
    clearCart() {
      const cartList = this.cartList.filter((it) => {
        return !this.cartChecked.includes(it.id);
      });
      this.$setStore({
        cartList,
        cartChecked: [],
      });
    },
  },
};
